<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Ajax extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('ajax_model');
		$this->load->library('flexigrid');
	}

	function ajax_users()
	{
		//List of all fields that can be sortable. This is Optional.
		//This prevents that a user sorts by a column that we dont want him to access, or that doesnt exist, preventing errors.
		$valid_fields = array('uuid','vendorcode','vfirstname','vlastname','villagename','vmobile');

		$this->flexigrid->validate_post('uuid','asc',$valid_fields);

		$records = $this->ajax_model->get_ajax_vendor();

		$this->output->set_header($this->config->item('json_header'));

		/*
		 * Json build WITH json_encode. If you do not have this function please read
		 * http://flexigrid.eyeviewdesign.com/index.php/flexigrid/example#s3 to know how to use the alternative
		 */
		$record_items = array();
		foreach ($records['records']->result() as $row)
		{
			$record_items[] = array($row->uuid,
			$row->uuid,
			$row->vendorcode,
			$row->vfirstname,
			$row->vlastname,
			$row->villagename,
			$row->vmobile,
			'<a href="'.site_url('users/form/'.$row->uuid).'"><img border=\'0\' src=\''.base_url().'public/images/close.png\'></a> '
			);
		}
		//Print please
		$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
	}


	//Delete Country
	function deletec()
	{
		$countries_ids_post_array = split(",",$this->input->post('items'));

		foreach($countries_ids_post_array as $index => $country_id)
		if (is_numeric($country_id) && $country_id > 1)
		$this->ajax_model->delete_country($country_id);

			
		$error = "Selected countries (id's: ".$this->input->post('items').") deleted with success";

		$this->output->set_header($this->config->item('ajax_header'));
		$this->output->set_output($error);
	}

	function ajax_truck()
	{

		//List of all fields that can be sortable. This is Optional.
		//This prevents that a user sorts by a column that we dont want him to access, or that doesnt exist, preventing errors.
		$valid_fields = array('larn','ticketid','extra_paymentdate','vendor_land_id','net_wght','cost_unt','totalcut_price','buynet','buynet1');

		$this->flexigrid->validate_post('extra_paymentdate','asc',$valid_fields);

		$records = $this->ajax_model->get_ajax_truck();

		$this->output->set_header($this->config->item('json_header'));

		/*
		 * Json build WITH json_encode. If you do not have this function please read
		 * http://flexigrid.eyeviewdesign.com/index.php/flexigrid/example#s3 to know how to use the alternative
		 */
		$record_items = array();
		foreach ($records['records']->result() as $row)
		{
				
			$record_items[] = array($row->larn.$row->ticketid,
			$row->larn,
			$row->ticketid,
			$row->extra_paymentdate,
			$row->vendor_land_id,
			$row->net_wght,
			$row->cost_unt,
			$row->totalcut_price,
			$row->buynet,
			$row->buynet1,
			'<a href=\'#\'><img border=\'0\' src=\''.base_url().'public/images/close.png\'></a> '
			);
		}
		//Print please
		$this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
	}

}
?>